<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="ThemeBucket">
    <link rel="shortcut icon" href="#" type="image/png">

    <title>Login</title>

    <!--引入公共的-->
    <div th:include="common :: commonheader"></div>

</head>

<body class="login-body">

<div class="container">

    <form class="form-signin" th:action="@{/login}" method="post">
        <div class="form-signin-heading text-center">
            <h1 class="sign-title">登录</h1>
            <img src="images/login-logo.png" alt=""/>
        </div>
        <div class="login-wrap">
            <label style="color: red" id="msg" th:text="${msg}"></label>
            <input type="text" id="username" name="username" th:value="${username}" class="form-control" placeholder="用户名" autofocus>
            <input type="password" id="password" name="password" class="form-control" placeholder="密码">
            <input id="code" placeholder="验证码" name="inputKaptcha" type="text" class="form-control-code"
                   style="width:140px">
            <!-- 验证码 显示 -->
            <img src="/captcha" style="height: 50px; width: 140px;" id="captcha" onclick="getvCode()" />

            <button class="btn btn-lg btn-login btn-block" id="login" type="submit">
                <i class="fa fa-check"></i>
            </button>

            <div class="registration">
                尚未注册?
                <a class="" th:href="@{/registration}">
                    注册
                </a>
            </div>
            <label class="checkbox">
                <input type="checkbox" id="remember" name="remember-me" value="true"> 记住我
                <span class="pull-right">
                    <a data-toggle="modal" href="#myModal"> 忘记密码?</a>

                </span>
            </label>

        </div>

        <!-- Modal -->
        <div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal" class="modal fade">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title">修改密码</h4>
                    </div>
                    <div class="modal-body">
                        <p>请输入邮箱来修改你的密码</p>
                        <input type="text" name="email" placeholder="Email" autocomplete="off" class="form-control placeholder-no-fix">

                    </div>
                    <div class="modal-footer">
                        <button data-dismiss="modal" class="btn btn-default" type="button">取消</button>
                        <button class="btn btn-primary" type="button">提交</button>
                    </div>
                </div>
            </div>
        </div>
        <!-- modal -->

    </form>

</div>



<!-- Placed js at the end of the document so the pages load faster -->

<!-- Placed js at the end of the document so the pages load faster -->
<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/modernizr.min.js"></script>
<script type="text/javascript">
    // 处理Cookie，记住用户名和密码
    var cookies = document.cookie.split(';');
    function getCookie(mkey){
        for(var i = 0; i < cookies.length; i++){
            var kv = cookies[i].split('=');
            if(kv[0].trim()==mkey){
                return kv[1].trim();
            }
        }
        return '';
    }
    // 处理Cookie，记住用户名和密码
    window.onload = function(){
        var username = getCookie("nms_username");
        var password = getCookie("nms_password");
        var remember = getCookie("nms_remember");
        if(remember == '1'){
            $("#username").val(username);
            $("#password").val(password);
            $("#remember").prop("checked", "checked");
        }
    };

    // 处理登录表单页面
    $(function () {
        // 处理登录
        $("#login").click(function () {
            // 获取用户名输入框里的内容
            let username = $("#username").val();
            if (username === "") {
                $("#msg").text("用户名为空！");
                // 防止提交
                return false;
            }
            // 获取密码输入框里的内容
            let password = $("#password").val();
            if (password === "") {
                $("#msg").text("密码为空！");
                // 防止提交
                return false;
            }
            // 处理验证码
            if ($("#code").val() === ""){
                $("#msg").text("验证码为空！");
                // 防止提交
                return false;
            }
            $("#msg").text("");
        });
    });
    // 点击验证码切换功能
    function getvCode() {
        document.getElementById("captcha").src="/captcha?t="+new Date().getTime();;
    }
</script>
</body>
</html>
